package bloom_filter

const (
	machine32 int = 32
	machine64 int = 64
)

type BitMap interface {
	Add(int)
	Contains(int) bool
	Remove(int)
}

type IntBitMap struct {
	size       int
	containers []int
}

func (ibm *IntBitMap) Add(val int) {
	r := val / machine64
	c := val % machine64
	ibm.containers[r] = ibm.containers[r] | (1 << c)
}

func (ibm *IntBitMap) Contains(val int) bool {
	r := val / machine64
	c := val % machine64
	return ((uint64(ibm.containers[r]) >> c) & 1) == 1
}

func (ibm *IntBitMap) Remove(int) {
	panic("implement me")
}

func DefaultBitMap() BitMap {
	return NewBitMap(1024)
}

func NewBitMap(size int) BitMap {
	return &IntBitMap{
		size:       size,
		containers: make([]int, size),
	}
}
